package com.fanxuankai.ksql.function.udf.datetime;

import com.fanxuankai.ksql.function.util.DateUtils;
import io.confluent.ksql.function.udf.Udf;
import io.confluent.ksql.function.udf.UdfDescription;
import io.confluent.ksql.function.udf.UdfParameter;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;

/**
 * @author fanxuankai
 */
@UdfDescription(name = "work_hours_date", description = "work hours date", author = "fanxuankai")
public class WorkHoursDate {
    @Udf
    public Date calc(@UdfParameter("val") Timestamp o, @UdfParameter("workHours") int workHours) {
        return o == null ? null : DateUtils.workHoursDate(o.getTime(), workHours);
    }

    @Udf
    public Date calc(@UdfParameter("val") Date o, @UdfParameter("workHours") int workHours) {
        return o == null ? null : DateUtils.workHoursDate(o.getTime(), workHours);
    }

    @Udf
    public Date calc(@UdfParameter("val") Time o, @UdfParameter("workHours") int workHours) {
        return o == null ? null : DateUtils.workHoursDate(o.getTime(), workHours);
    }
}
